#include "PDL.h"


namespace iap {
	
	
	PDL_ItemInfo* itemInfo;
	PDL_ItemCollection* items;
	
	
	void InAppPurchase_FreeItemCollection () {
		
		PDL_FreeItemCollection (items);
		
	}
	
	
	void InAppPurchase_FreeItemInfo () {
		
		PDL_FreeItemInfo (itemInfo);
		
	}
	
	
	const char* InAppPurchase_GetAvailableItemsJSON () {
		
		items = PDL_GetAvailableItems ();
		
		if (items) {
			
			const char* itemsJSON = PDL_GetItemCollectionJSON (items);
			atexit (InAppPurchase_FreeItemCollection);
			
			if (itemsJSON) {
				
				return itemsJSON;
				
			}
			
		}
		
		return NULL;
		
	}
	
	
	const char* InAppPurchase_GetItemDetailsJSON (const char* itemID) {
		
		itemInfo = PDL_GetItemInfo (itemID);
		
		if (itemInfo) {
			
			const char* itemDetailsJSON = PDL_GetItemJSON (itemInfo);
			atexit (InAppPurchase_FreeItemInfo);
			
			if (itemDetailsJSON) {
				
				return itemDetailsJSON;
				
			}
			
		}
		
		return NULL;
		
	}
	
	
	void InAppPurchase_PurchaseItem (const char* itemID, int quantity, const char* vendorData) {
		
		PDL_ItemReceipt* itemReceipt = PDL_PurchaseItem (itemID, quantity, vendorData);
		
		if (itemReceipt) {
			
			const char* itemReceiptJSON = PDL_GetItemReceiptJSON (itemReceipt);
			
		}
		
	}
	
	
}